﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;
using System.Web.Security;

namespace Recetas_Web
{
    public partial class MasterPage : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            Response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(-1));
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            Response.Cache.SetNoStore(); 

            if (System.Web.HttpContext.Current.User != null && System.Web.HttpContext.Current.User.Identity.IsAuthenticated)
            {
                LinkButton1.Visible = false;
                LinkButton2.Visible = true;
                if (Session["Name"] != null)
                {
                    Label1.Text = "Hola " + (string)Session["Name"].ToString() + "!";
                }
                Menu1.Items.RemoveAt(2);
                MenuItem Perfil = new MenuItem();
                Menu1.Items.AddAt(2, Perfil);
                Perfil.Text = "PERFIL";
                Perfil.Value = "Perfil";
                Perfil.NavigateUrl = "Perfil_Usuarios.aspx";
            }
            else {
                LinkButton1.Visible = true;
                LinkButton2.Visible = false;
            }
        }

        protected void LinkButton1_Click(object sender, EventArgs e)
        {
            Response.Redirect("Login.aspx");
        }

        protected void LinkButton2_Click(object sender, EventArgs e)
        {
            Session.Abandon();
            Session.Clear();
            FormsAuthentication.SignOut();
            Response.Redirect("Login.aspx");
        }
    }
}